﻿/**
* Title:"项目";
*
* Description:
*        功能：
*
* Author:Tongwel
*
* Date:2018.6
*
* Modify:
*/
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

//执行背包添加功能
public class AddGoodCommand : ICommand
{
    PackProxy packProxy = PackProxy.Instance;
    GoodProxy goodProxy = GoodProxy.Instance;

    public void Excute(INotifier notifier)
    {
        PackModel model = null;
        //1.判断物体是不是存在
        int id = 1;
        //物体不存在就返回出来
        if (!int.TryParse(notifier.body.ToString(),out id))
        {
            return;
        }

        if (packProxy.TryGetGoodModel(id, out model))
        {
            //添加数据
            model.GoodCount++;
            //更新数据
            packProxy.Update(model);
        }
        //2.判断背包是否有物品
        else if (packProxy.IsFull())
        {
            return;
        }
        //3.添加
        else
        {
            //获取一个空背包
            model = packProxy.GetEmptyModel();
            model.GoodID = id;
        }

    }
}
